package com.huangmb.anymark.server.controller;

import com.huangmb.anymark.server.dto.Response;
import com.huangmb.anymark.server.utils.QiniuUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 上传图片
 * @author hmb
 * @version 1.0
 * @since 2016/5/17 16:18
 */
@RestController
@RequestMapping(value = "/file")
public class FileController {
    @RequestMapping(value = "/put_policy", method = RequestMethod.GET)
    public Response getPutPolicy(@RequestParam(name = "policy") String putPolicy) {

        String encodedPutPolicy = QiniuUtils.getPutPolicy(putPolicy);
        if (encodedPutPolicy == null) {
            return new Response(Response.CODE_BAD_PARAMETER, Response.MSG_BAD_PARAMETER, null);
        }
        return Response.buildSuccess(encodedPutPolicy);
    }
}
